package org.jsbd.boss.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.jsbd.boss.domian.statistics.SimulatorActionNewDto;
import org.jsbd.boss.domian.statistics.SimulatorActionNewStatisticsVo;
import org.jsbd.boss.service.ISimulatorActionNewStatisticsService;
import org.jsbd.boss.util.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/simulator/action/statistics")
public class SimulatorActionNewStatisticsController {

  private static final Logger logger = LoggerFactory.getLogger(SimulatorActionNewStatisticsController.class);
  

  @Autowired
  private ISimulatorActionNewStatisticsService simulatorActionNewStatisticsService;

  /**
   * 新模拟器行为统计页面
   * @return
   */
  	@RequestMapping(value = "/")
  	public String toPage() {
  		return "simulatorAction/list";
  	}
  
  	/**
  	 * 新模拟器行为统计数据
  	 * @param model
  	 * @param issueStatisticsVo
  	 * @return
  	 */
  	@RequestMapping(value = "/list", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> list(Model model, SimulatorActionNewStatisticsVo saVo) {
  		Map<String, Object> map = new HashMap<String, Object>();
  		
  		String startTime = saVo.getStartTime();
  		String endTime = saVo.getEndTime();
  		if (StringUtils.isBlank(startTime) && StringUtils.isBlank(endTime)) {
  			saVo.setStartTime(DateUtil.getDayBeforeDate(DateUtil.DATE_PATTEN_YYMMDD, 60));
  		}
  		
  		List<SimulatorActionNewDto> yAxis =  simulatorActionNewStatisticsService.selectRecord(saVo);
  		List<String> xAxis =  simulatorActionNewStatisticsService.selectDays(saVo);
  		
		map.put("xAxis", xAxis);
		map.put("yAxis", yAxis);
		return map;
	}
  	
}
